package chances.epg.navigator;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.servlet.http.HttpServletRequest;

import chances.epg.commons.log.EpgLogFactory;
import chances.epg.navigator.context.AccessContext;
import chances.epg.session.UserSession;


public class EpgLogUtils {
	private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static final String PARAM_PAGEINDEX = "p_idx";
	
	/**
	 * 记录访问日志.
	 * @param context
	 */
	public static void logAccess(HttpServletRequest request,AccessContext context,UserSession userSession) {
		if(userSession == null){
			return;
		}
		StringBuffer info = new StringBuffer();
		
		info.append(format.format(Calendar.getInstance().getTime())).append("|");
		info.append(userSession.getUserId()).append("|");
		/*info.append(context.getSiteCode()).append("|");
		
		//根展示栏目的编码，即看吧编码
		Biz biz = context.getBiz();
		if(biz != null){
			info.append(biz.getRootCode()).append("|");
		}else{
			info.append(context.getBizCode()).append("|");
		}
		
		info.append(context.getBizCode()).append("|");
		info.append(context.getContainerType()).append("|");
		info.append(context.getContainerCode()).append("|");
		info.append(context.getItemIndex()).append("|");
		info.append(context.getParentContentType()).append("|");
		info.append(context.getParentContentCode()).append("|");
		info.append(context.getContentType()).append("|");
		info.append(context.getContentCode()).append("|");
		info.append(context.getDirect()).append("|");
		
		//page index
		String pIndex = request.getParameter(PARAM_PAGEINDEX);
		if(StringUtils.isNotBlank(pIndex) 
				&& StringUtils.isNumeric(pIndex)){
			info.append(pIndex);
		}else{
			info.append("1");//default 1
		}
		info.append("|");*/
		
		info.append(request.getRequestURL().toString());
		
		EpgLogFactory.getAccessLogger().info(info.toString());
	}
	

}
